package com.darkness.rpc.registercenter.local;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class LocalRegister {

    // 先group区分, 再itfClass区分, 再version区分, 最终得到一个实现类结果
    private static final Map<String, Map<String, Map<String, Class<?>>>> implServiceMap = new ConcurrentHashMap<>();

    public static Class<?> getImplClass(String group, String itfClassName, String version) {
        return implServiceMap.get(group).get(itfClassName).get(version);
    }

    public static void registerLocal(String group, String itfClassName, String version, Class<?> implClass) {
        Map<String, Map<String, Class<?>>> itfMap = implServiceMap.computeIfAbsent(group, k -> new HashMap<>());
        Map<String, Class<?>> versionMap = itfMap.computeIfAbsent(itfClassName, k -> new HashMap<>());
        versionMap.put(version, implClass);
    }

}
